package org.ourgrid.acceptance.aggregator;

import static org.junit.Assert.assertTrue;

import org.junit.Test;
import org.ourgrid.acceptance.util.aggregator.Req_602_Util;
import org.ourgrid.aggregator.AggregatorComponent;
import org.ourgrid.aggregator.AggregatorConstants;
import org.ourgrid.aggregator.controller.CommunityStatusProviderNotificationController;
import org.ourgrid.reqtrace.ReqTest;

public class Req_602_Test extends AggregatorAcceptanceTestCase {
	
	Req_602_Util req_602_Util = new Req_602_Util(getComponentContext());
	
	/*
	 * Create an Aggregator;
	 * Start the Aggregator with the public key "wrongPublicKey" - Verify if the following warn message was logged:
     *     o An unknown entity tried to start the Aggregator. Only the local modules can perform this operation. 
     *       Unknown entity public key: [senderPublicKey].
	 *
	 */
	@ReqTest(test = "AT-602.1", reqs = "start component - wrong public key")
	@Test public void test_AT_602_1_StartAggregatorWithWrongPublicKey() throws Exception {
		//Creates and starts with the public key "wrongPublicKey"
		req_602_Util.startAggregatorWithWorngPublicKey("wrongPublicKey");
		
	}
	
	/*
	 * Create an Aggregator;
	 * Start an Aggregator with the correct public key;
	 * Verify if the following message was logged:
     *     o "Aggregator has been successfully started."
	 * Get(lookup) the remote object "AGGREGATOR_DS_MONITOR_OBJECT" and verify if its type is:
     *     o org.ourgrid.aggregator.controller.CommunityStatusProviderNotificationController
	 * Verify if the ControlClient received the operation succeed message.
	 *
	 */
	@ReqTest(test = "AT-602.2", reqs = "start component")
	@Test public void test_AT_602_2_StartAggregator() throws Exception {
		
		//Start an Aggregator with the correct public key;
		AggregatorComponent component = req_602_Util.startAggregator();
	
		//Get(lookup) the remote object "AGGREGATOR_DS_MONITOR_OBJECT" and verify if its type
		assertTrue(isBound(component, AggregatorConstants.DS_MONITOR_OBJECT_NAME, 
				CommunityStatusProviderNotificationController.class));

	}
	
	/*
	 * Create an Aggregator;
	 * Start an Aggregator with the correct public key;
	 * Start the same Aggregator again with the correct public key.
	 * Verify if the Control Result Operation contains an exception whose type is:
     *     o br.edu.ufcg.lsd.commune.container.control.ComponentAlreadyStartedException
	 *
	 */
	@ReqTest(test = "AT-602.3", reqs = "start component - alredy started")
	@Test public void test_AT_602_3_StartAggregatorAlreadyStarted() throws Exception {
		
		//Start an Aggregator with the correct public key;
		AggregatorComponent component = req_602_Util.startAggregator();
		
		//Start the same Aggregator again with the correct public key.
		req_602_Util.startAggregatorAgain(component);
	}

}
